$.mobile.defaultPageTransition = 'none';
$.mobile.defaultDialogTransition = 'none';
$.mobile.page.prototype.options.addBackBtn = true;
$.mobile.useFastClick = false;
var inland = "";
var outland = "";

/**
 * 国内机场
 */
var A = [];
var B = [];
var C = [];
var D = [];
var E = [];
var F = [];
var G = [];
var H = [];
var I = [];
var J = [];
var K = [];
var L = [];
var M = [];
var N = [];
var O = [];
var P = [];
var Q = [];
var R = [];
var S = [];
var T = [];
var U = [];
var V = [];
var W = [];
var X = [];
var Y = [];
var Z = [];
var hotCode = [];
var ACode = [];
var BCode = [];
var CCode = [];
var DCode = [];
var ECode = [];
var FCode = [];
var GCode = [];
var HCode = [];
var ICode = [];
var JCode = [];
var KCode = [];
var LCode = [];
var MCode = [];
var NCode = [];
var OCode = [];
var PCode = [];
var QCode = [];
var RCode = [];
var SCode = [];
var TCode = [];
var UCode = [];
var VCode = [];
var WCode = [];
var XCode = [];
var YCode = [];
var ZCode = [];
var XCode = [];
var hotPinyin = [];
var APinyin = [];
var BPinyin = [];
var CPinyin = [];
var DPinyin = [];
var EPinyin = [];
var FPinyin = [];
var GPinyin = [];
var HPinyin = [];
var IPinyin = [];
var JPinyin = [];
var KPinyin = [];
var LPinyin = [];
var MPinyin = [];
var NPinyin = [];
var OPinyin = [];
var PPinyin = [];
var QPinyin = [];
var RPinyin = [];
var SPinyin = [];
var TPinyin = [];
var UPinyin = [];
var VPinyin = [];
var WPinyin = [];
var XPinyin = [];
var YPinyin = [];
var ZPinyin = [];
var XPinyin = [];
var citys = [];

citys = [A, B, C, D, E, F, G, H, J, K, L, M, N,
    		P, Q, S, T, W, X, Y, Z ];

codes = [ACode, BCode, CCode, DCode, ECode,
  		FCode, GCode, HCode, JCode, KCode, LCode,
  		MCode, NCode, PCode, QCode, SCode, TCode,
  		WCode, XCode, YCode, ZCode ];

pinyins = [APinyin, BPinyin, CPinyin, DPinyin,
		EPinyin, FPinyin, GPinyin, HPinyin, JPinyin,
		KPinyin, LPinyin, MPinyin, NPinyin, PPinyin,
		QPinyin, SPinyin, TPinyin, WPinyin, XPinyin,
		YPinyin, ZPinyin ];
var titleArr = ['A', 'B', 'C', 'D', 'E', 'F',
 				'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q',
 				'S', 'T', 'W', 'X', 'Y', 'Z' ];

/**
 * 国际机场
 */
var AI = [];
var BI = [];
var CI = [];
var DI = [];
var EI = [];
var FI = [];
var GI = [];
var HI = [];
var II = [];
var JI = [];
var KI = [];
var LI = [];
var MI = [];
var NI = [];
var OI = [];
var PI = [];
var QI = [];
var RI = [];
var SI = [];
var TI = [];
var UI = [];
var VI = [];
var WI = [];
var XI = [];
var YI = [];
var ZI = [];
var ACodeI = [];
var BCodeI = [];
var CCodeI = [];
var DCodeI = [];
var ECodeI = [];
var FCodeI = [];
var GCodeI = [];
var HCodeI = [];
var ICodeI = [];
var JCodeI = [];
var KCodeI = [];
var LCodeI = [];
var MCodeI = [];
var NCodeI = [];
var OCodeI = [];
var PCodeI = [];
var QCodeI = [];
var RCodeI = [];
var SCodeI = [];
var TCodeI = [];
var UCodeI = [];
var VCodeI = [];
var WCodeI = [];
var XCodeI = [];
var YCodeI = [];
var ZCodeI = [];
var XCodeI = [];
var APinyinI = [];
var BPinyinI = [];
var CPinyinI = [];
var DPinyinI = [];
var EPinyinI = [];
var FPinyinI = [];
var GPinyinI = [];
var HPinyinI = [];
var IPinyinI = [];
var JPinyinI = [];
var KPinyinI = [];
var LPinyinI = [];
var MPinyinI = [];
var NPinyinI = [];
var OPinyinI = [];
var PPinyinI = [];
var QPinyinI = [];
var RPinyinI = [];
var SPinyinI = [];
var TPinyinI = [];
var UPinyinI = [];
var VPinyinI = [];
var WPinyinI = [];
var XPinyinI = [];
var YPinyinI = [];
var ZPinyinI = [];
var XPinyinI = [];

citysI = [AI, BI, CI, DI, FI, GI, HI, JI, KI,
			LI, MI, NI, PI, QI, SI, TI, WI, XI, YI, ZI ];

codesI = [ACodeI, BCodeI, CCodeI, DCodeI,
			FCodeI, GCodeI, HCodeI, JCodeI, KCodeI, LCodeI,
			MCodeI, NCodeI, PCodeI, QCodeI, SCodeI, TCodeI,
			WCodeI, XCodeI, YCodeI, ZCodeI ];
pinyinsI = [APinyinI, BPinyinI, CPinyinI,
				DPinyinI, FPinyinI, GPinyinI, HPinyinI,
				JPinyinI, KPinyinI, LPinyinI, MPinyinI,
				NPinyinI, PPinyinI, QPinyinI, SPinyinI,
				TPinyinI, WPinyinI, XPinyinI, YPinyinI,
				ZPinyinI ];
var titleArrI = ['A', 'B', 'C', 'D', 'F', 'G',
		'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'S',
		'T', 'W', 'X', 'Y', 'Z' ];
/**
 * 初始化城市集合
 */
function initAirport(){
	var dataObj=eval("("+json+")");
	for(var i = 0; i < dataObj.airportList.length; i++){
		if(dataObj.airportList[i].domestic == "1" ){
			var aptShortPy = dataObj.airportList[i].aptShortPy;
			if(aptShortPy!=""&&aptShortPy!=null){
				var pinyinStart = aptShortPy.substring(0, 1);
				for(var j = 0; j<titleArr.length; j++){
					if(pinyinStart == titleArr[j]){
						citys[j].push(dataObj.airportList[i].aptName);
						codes[j].push(dataObj.airportList[i].aptCode);
						pinyins[j].push(dataObj.airportList[i].aptShortPy);
					}
				}
			}
		}else if(dataObj.airportList[i].domestic == "0"){
			var aptShortPy = dataObj.airportList[i].aptShortPy;
			if(aptShortPy!=""&&aptShortPy!=null){
				var pinyinStart = aptShortPy.substring(0, 1);
				for(var j = 0; j<titleArrI.length; j++){
					if(pinyinStart == titleArrI[j]){
						var country = "";
						if(dataObj.airportList[i].country!=""&&dataObj.airportList[i].country!=null){
							country = " [ "+dataObj.airportList[i].country+" ]";
						}
						citysI[j].push(dataObj.airportList[i].aptName + country);
						codesI[j].push(dataObj.airportList[i].aptCode);
						pinyinsI[j].push(dataObj.airportList[i].aptShortPy);
					}
				}
			}
		}
	}
}
/**
 * 初始化国内机场html
 */
function initInland(){
	for ( var i = 0; i < titleArr.length; i++) {
		if(i==0)
			inland += "<li data-role='list-divider' data-theme='d' id='top_city'>"+titleArr[i]+"</li>";
		else
			inland += "<li data-role='list-divider' data-theme='d' id='"+titleArr[i]+"'>"+titleArr[i]+"</li>";
		var temp = '';
		if (i < titleArr.length) {
			var content = citys[i];
			var pinyin = pinyins[i];
			for ( var j = 0; j < content.length; j++) {
				temp +="<li style='background:#fff' data-icon='false' data-theme='d'><a href='javascript:;' onclick='change(this);' title='" + content[j] + "' id='" + codes[i][j] + "'><em class='hide'>" + pinyin[j] + "</em>" + content[j] + "</a></li>";
			}
		}	
		inland += temp;
	}
}
/**
 * 初始化国际机场html
 */
function initOutland(){
	for ( var i = 0; i < titleArrI.length; i++) {
		if(i==0)
			outland += "<li data-role='list-divider' data-theme='d' id='top_city'>"+titleArrI[i]+"</li>";
		else
			outland += "<li data-role='list-divider' data-theme='d' id='"+titleArrI[i]+"'>"+titleArrI[i]+"</li>";
		var temp = '';
		if (i < titleArrI.length) {
			var content = citysI[i];
			var pinyin = pinyinsI[i];
			for ( var j = 0; j < content.length; j++) {
				temp +="<li style='background:#fff' data-icon='false' data-theme='d'><a href='javascript:;' onclick='change(this);' title='" + content[j] + "' id='" + codesI[i][j] + "'><em class='hide'>" + pinyin[j] + "</em>" + content[j] + "</a></li>";
			}
		}	
		outland += temp;
	}
}
//alert("code:"+city.aptCode+",aptName:"+city.aptName+",cityName:"+city.cityName+",aptFullPy:"+city.aptFullPy+",aptShortPy:"+city.aptShortPy+",domestic:"+city.domestic+",country:"+city.country); 
/**
 * 初始化界面信息
 */
function initABC(){
 	var _wh = $(window).height();
    $('.abc a').css('line-height', ((_wh - 80) / 23) + 'px');
    $('.abc a').on('tap', function () {
        var _id = $(this).text();
        if (_id == '常用') {
            _id = 'top_city';
        }
        var _offset = $('#' + _id).offset();
        $(document).scrollTop(_offset.top - 10);
    }); 
}
/**
 * 初始化查询条件
 */
function initCond(){
	var today = new Date();
    var weekday=new Array(7);
    weekday[1]="星期一";
    weekday[2]="星期二";
    weekday[3]="星期三";
    weekday[4]="星期四";
    weekday[5]="星期五";
    weekday[6]="星期六";
    weekday[0]="星期日";                            
    var y=today.getFullYear();
    var m=today.getMonth()+1;
    if(m<10)
    	m="0"+m;
    var td=today.getDate();
    if(td<10)
    	td="0"+td;
    var w=weekday[today.getDay()];
    $("#day").html(y+"-"+m+"-"+td);
    $("#date").attr("value",y+""+m+""+td);
    $("#dptDate").attr("value",y+"-"+m+"-"+td);
    $("#week").html(w);
    $("#orgCode").val("PEK");
	$("#dstCode").val("SHA");
	$("#flightNum").val("");
}
$(function() {
	initCond();
	var title = "航班动态-查询";
   	$("#mainPage #pagetitle").html(title);
    $("#pageback").hide();
    initABC();
    initAirport();
	initInland();
	initOutland();
	$("#city_list").html(inland);
	$("#city_list").listview('refresh');
});
/**
 * 切换国内
 */
function inAirport(){
	$("#city_list").html(inland);
	$("#city_list").listview('refresh');
	$("#menu_l").css({"background":"url(../static/img/imgs/bnt480_c.png) repeat-x"});
	$("#menu_r").css({"background":"url(../static/img/imgs/bnt480_b.png) repeat-x"});
}
/**
 * 切换国际
 */
function outAirport(){
	$("#city_list").html(outland);
	$("#city_list").listview('refresh');
	$("#menu_r").css({"background":"url(../static/img/imgs/bnt480_c.png) repeat-x"});
	$("#menu_l").css({"background":"url(../static/img/imgs/bnt480_b.png) repeat-x"});
}

/**
 * 提交表单
 */
function submitForm(){
	var flag = $("#flag").val();
	if(flag=="flightNo"){
		var airCode = $("#airCode").val();
		if(airCode.trim()==""){
			alert("航空代码不能为空");
			return false;
		}else{
			$("#airlineCd").attr("value", airCode);
		}
		var flightno = $("#flightNo").val();
		if(flightno.trim()==""){
			alert("航班号不能为空！");
			return false;
		}else{
			$("#flightNum").attr("value", $("#flightNo").val());
		}
		var day = $("#day").html();
		if(day.trim()==""){
			alert("日期不能为空！");
			return false;
		}else{
			$("#dptDate").attr("value", day);
		}
	}else if(flag=="city"){
		var airCode1 = $("#airCode1").val();
		if(airCode1.trim()==""){
			alert("航空代码不能为空");
			return false;
		}else{
			$("#airlineCd").attr("value", airCode1);
		}
		var orgCode = $("#orgCode").val();
		if(orgCode.trim()==""){
			alert("出发城市不能为空！");
			return false;
		}else{
			$("#depAirptName").attr("value",$("#orgCity").html());
			$("#depAirptCd").attr("value", orgCode);
		}
		var dstCode = $("#dstCode").val();
		if(dstCode.trim()==""){
			alert("到达城市不能为空！");
			return false;
		}else{
			$("#arrAirptName").attr("value",$("#dstCity").html());
			$("#arrAirptCd").attr("value", dstCode);
		}
		var day = $("#day").html();
		if(day.trim()==""){
			alert("日期不能为空！")
			return false;
		}else{
			$("#dptDate").attr("value", day);
		}
	}else{
		return false;
	}

	$("#mainform").submit();
}

/**
 * 打开城市选择列表
 */
function opencity(fg){
	var city = "";
	if(fg=="1") city = "出发城市";
	else city = "到达城市";
	$("#city h1").attr("id", fg);
	$("#city #pagetitle").html(city);
	$.mobile.changePage('#city', 'none', false, false);
}
/**
 * 选择城市
 */
function change(th){
    var ct = th.title;
    var code = th.id;
    var fg = $("#city h1").attr("id");
    if(fg=="1"){
    	$("#orgCity").html(ct);
    	$("#orgCode").attr("value", code);
    }else{
    	$("#dstCity").html(ct);
    	$("#dstCode").attr("value", code);
    }
    $.mobile.changePage('#mainPage', 'none', false, false);
}
